var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    shopInfo:{
      type:Object,
      value:{},
      observer(newVal, oldVal, changedPath) {
        
      }
    },
    userInfo:{
      type:Object,
      value:{},
      observer(newVal, oldVal, changedPath) {

      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    teamSeat:app.teamSeat,
    supplyChannel_sort:app.supplyChannel_sort,
    selected:app.supplyChannel,
    theme:app.theme,
    avatar:"",//分销团长头像
    value: "",
    content:"",
    noticeText:"",
    isNotice:false
  },
  // 当切换模式改变
  attached(){
    this.into();
  },
  ready() { 
    this.into();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getShopInfo(){
      let user=app.functions.getLocalStorage("user");
      let shareid = app.functions.getLocalStorage("shareUserId");
      // console.info(shareid);
      if(user.isteam==3){
        if(!app.functions.isEmpty(shareid)){
          app.api.shopMsg({id: shareid},(response)=>{
            this.setData({
              avatar:response.data.avatar
            })
          },(error)=>{
            
          })
        }
      }else{
        if(!app.functions.isEmpty(shareid)){
          app.api.shopMsg({id: shareid},(response)=>{
            this.setData({
              avatar:response.data.avatar
            })
          },(error)=>{
    
          })
        }
      }
    },
    into(){
      this.setData({
        supplyChannel_sort:app.supplyChannel_sort,
        selected:app.supplyChannel,
        theme:app.theme,
        teamSeat:app.teamSeat
      },()=>{
        this.shopInfo();
        this.getShopInfo();
      })
    },
    getSelected(e){
      this.into();
      this.setData({
        selected: e.currentTarget.dataset.index
      },()=>{
          let pages = getCurrentPages(); //获取加载的页面
          let currentPage = pages[pages.length - 1]; //获取当前页面的对象
          let url = currentPage.route;//当前页面url
          app.cache[url].getSelected(this.data.selected);
      })
    },
    onClickSel(){
        let user=app.functions.getLocalStorage("user");
        if(app.functions.isEmpty(user)){
          wx.redirectTo({
            url: '/pages_subpack/pop_shop_address/pop_shop_address'
          })
          return;
        }
        if(this.data.userInfo.isteam!=3||(this.data.userInfo.serviceType==1&&this.data.userInfo.isteam==3&&this.data.userInfo.mentionId=='')){
          wx.redirectTo({
            url: '/pages_subpack/pop_shop_address/pop_shop_address'
          })
        };
        
      },
      // 判断是否打样
      shopInfo(){
        let shop = app.functions.getLocalStorage("shop");
        if (app.functions.isEmpty(shop)) return;

        if (new Date((shop.sleepStartTime).replace(/-/g, '/')).getTime() < new Date().getTime() && new Date().getTime() < new Date((shop.sleepEndTime).replace(/-/g, '/')).getTime()){
          this.setData({
            shopInfo:shop,
            isNotice:true,
            noticeText: '店铺打烊  ' + app.functions.dateTimeFormat(shop.sleepStartTime, 'YYYY-MM-DD HH:mm') + '至' + app.functions.dateTimeFormat(shop.sleepEndTime,'YYYY-MM-DD HH:mm')
          })
        }else{
          this.setData({
            shopInfo:shop,
            isNotice: false
          },()=>{
            this.ShopNotice();
          })
        }
      },
      // 公告
      ShopNotice(){
        let shop = app.functions.getLocalStorage("shop");
        let params={
          centerId: shop.centreId
        };
     
        app.api.ShopNotice(params,(response)=>{
  
          if(response.data.rows.length>0){
            this.setData({
              content:response.data.rows[0].content
            })
          }else{
            this.setData({
              content:''
            })
          }
        },(e)=>{
          app.functions.showToast(e.msg);
        })
      }

  }
})
